#!/usr/bin/env python
#author:  sixther.me
#date : 2014-08-18
import sys
import os
import re

def check_disk(check_type,alert_value):
        disk_usage={}
        disk_usage_alert={}
        check_list={'block':'df -P | tail -n +2','inode':'df -P -i | tail -n +2'}
        for i in os.popen(check_list[check_type]):
                disk_usage[i.split()[5]]=i.split()[4][:-1]
        for i in disk_usage:
                if int(disk_usage[i]) > int(alert_value):
                        disk_usage_alert[i]=disk_usage[i]
        if not disk_usage_alert:
                print 0
        else:
                for i in disk_usage_alert:
                        print i + ':' + disk_usage_alert[i] + '%,',
def get_real_in(vitual_interface):
        in_list={'eth0':'bond0','eth1':'bond1'}
        if in_list[vitual_interface] in interface_list:
                return in_list[vitual_interface]
        else:
                return vitual_interface
def check_net_traffic(interface,check_type):
        net_data_1={}
        net_data_2={}
        type_list={'in':'0','out':'8'}
        net_file='/proc/net/dev'
        net_file_df=open(net_file)
        net_file_list=net_file_df.readlines()
        global interface_list
        interface_list=[]
        for i in net_file_list:
                if re.search(':',i):
                        interface_list.append(i.split(':')[0].strip())
        net_data=os.popen('cat ' + net_file +  '| grep ' + get_real_in(interface) ).readline().split(':')[1].split()[int(type_list[check_type])]
        print int(net_data) * 8

if __name__ ==  '__main__':
        status_data_array={
                'block_usage':'check_disk(\'block\',sys.argv[2])',
                'inode_usage':'check_disk(\'inode\',sys.argv[2])',
                'eth0_in_traffic':'check_net_traffic(\'eth0\',\'in\')',
                'eth0_out_traffic':'check_net_traffic(\'eth0\',\'out\')',
                'eth1_in_traffic':'check_net_traffic(\'eth1\',\'in\')',
                'eth1_out_traffic':'check_net_traffic(\'eth1\',\'out\')',
        }
        eval(status_data_array[sys.argv[1]])
